<?php
declare (strict_types = 1);

namespace app\index\business;

use app\common\business\BaseBusiness;

#[path('/index/business', 'file path')]
#[class('User', 'User data handel')]
class User extends BaseBusiness
{
    public function __construct()
    {
    }

    public function login(string $username = '', string $passwd = '')
    {
        $user_data = config('user_data');

        // 验证用户名和密码
        foreach ($user_data as $key => $value) {
            if ($value['username'] !== $username) {
                throw new \think\Exception("用户名不存在");
            }
            if ($value['password'] !== $passwd) {
                throw new \think\Exception("密码错误");
            }

            $data = [
                'username' => $value['username'],
                'nickname' => $value['nickname'],
                'img'      => $value['img'],
            ];
        }

        return $data;
    }
}
